<?php

namespace App\Kuafu\WaiMai\Model;

use App\Kuafu\Base\Model\Traits\KfWaiMaiSplit;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Kuafu\Base\Model\BaseModel;

class WaiMaiSecureCardModel extends BaseModel
{
    use HasFactory;
    use KfWaiMaiSplit;

    protected $connection = 'mysqlWaiMai';
    protected $table      = 'waimai_secure_cards'; //表名
    protected $primaryKey = 'id';
    protected $modelCached = true;
    public $timestamps  = false;

    protected $fillable = [
        'shopId',
        'cardDetailList',
        'tips',
        'date',
        'createdAt',
    ];

    public function getCardDetailListFormatAttribute()
    {
        return json_decode($this->cardDetailList, true);
    }

    public function addData(int $shopId, int $date, string $cardDetailList, string $tips)
    {
        return self::suffix($shopId)->create([
            'shopId'         => $shopId,
            'date'           => $date,
            'cardDetailList' => $cardDetailList,
            'tips'           => $tips,
            'createdAt'      => time(),
        ]);
    }

    public function delData(int $shopId, int $date)
    {
        return self::suffix($shopId)->where('shopId', $shopId)->where('date', $date)->delete();
    }
}
